import 'package:flutter/material.dart';
import 'package:flutter_demo/src/page/Basic/index.dart';
import 'package:flutter_demo/src/page/Container/index.dart' as ContainerPage;
import 'package:flutter_demo/src/page/Layout/index.dart';
import 'package:flutter_demo/src/page/Scroll/index.dart';
import 'package:flutter_demo/src/page/Tools/index.dart';

class CustomTabBar extends StatefulWidget {
  @override
  TabBarState createState() {
    return new TabBarState();
  }
}

class TabBarState extends State {
  int _selectedIndex = 1;
  String titleText = '基础';
  void _onItemTapped(int index, BuildContext context) {
    setState(() {
      _selectedIndex = index;
      titleText = ['基础', '布局', '容器', '可滚动', '功能'][index];
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(title: Text(titleText)),
        body: <Widget>[
          Basic(),
          Layout(),
          ContainerPage.Container(),
          Scroll(),
          Tools()
        ][_selectedIndex],
        bottomNavigationBar: BottomNavigationBar(
          items: <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              icon: Icon(Icons.account_balance),
              title: Text('基础'),
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.view_quilt),
              title: Text('布局'),
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.settings_overscan),
              title: Text('容器'),
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.list),
              title: Text('可滚动'),
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.pan_tool),
              title: Text('功能'),
            ),
          ],
          currentIndex: _selectedIndex,
          fixedColor: Colors.blue,
          onTap: (index) => _onItemTapped(index, context),
          type: BottomNavigationBarType.fixed,
        ));
  }
}
